package TeamR3.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import TeamR3.entity.Customer;
import TeamR3.entity.MyJsonObject;
import TeamR3.service.CustomerService;

@Controller
public class TeamR3_Customer_Controller {
	@Autowired
	private CustomerService customerService = null;

	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}
	
	@RequestMapping("/queryCustomerInfo.TeamR3")
	public @ResponseBody MyJsonObject queryCustomerInfo(
			@RequestParam(value="identity") long identity, 
			@RequestParam(value="customer_name") String customer_name) {
		List<Customer> list = customerService.queryCustomerInfo(identity, customer_name);
		if(list!=null){
			return new MyJsonObject(200, "会员查询成功", list);
		}else return new MyJsonObject(201, "会员查询失败");
	}

	@RequestMapping("/addCustomerInfo.TeamR3")
	public @ResponseBody MyJsonObject addCustomerInfo(
			@RequestParam(value="identity") long identity, 
			@RequestParam(value="customer_name") String customer_name,
			@RequestParam(value="customer_tel") String customer_tel, 
			@RequestParam(value="customer_point") int customer_point) {
		int affectedRow = customerService.addCustomerInfo(identity, customer_name, customer_tel, customer_point);
		if(affectedRow!=0){
			return new MyJsonObject(200, "会员添加成功", affectedRow);
		}else return new MyJsonObject(201, "会员添加失败");
	}
	
	@RequestMapping("/modifyCustomerInfo.TeamR3")
	public @ResponseBody MyJsonObject modifyCustomerInfo(
			@RequestParam(value="identity") long identity, 
			@RequestParam(value="customer_name") String customer_name,
			@RequestParam(value="customer_tel") String customer_tel, 
			@RequestParam(value="customer_point") int customer_point) {
		int affectedRow = customerService.modifyCustomerInfo(identity, customer_name, customer_tel, customer_point);
		if(affectedRow!=0){
			return new MyJsonObject(200, "会员修改成功", affectedRow);
		}else return new MyJsonObject(201, "会员修改失败");
	}
	
	@RequestMapping("/delCustomerInfo.TeamR3")
	public @ResponseBody MyJsonObject delCustomerInfo(
			@RequestParam(value="identity") long identity) {
		int affectedRow = customerService.delCustomerInfo(identity);
		if(affectedRow!=0){
			return new MyJsonObject(200, "会员删除成功", affectedRow);
		}else return new MyJsonObject(201, "会员删除失败");
	}

}
